package net.muchine.test.strophe.core.configuration;

import net.muchine.test.strophe.core.configuration.loader.PropertyLoader;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.FactoryBean;

public class ConfigurationFactoryBean implements FactoryBean<Configuration> {
	private final Log log = LogFactory.getLog(this.getClass());
	private String location;
	
	public Configuration getObject() throws Exception {
		if (location == null)
			throw new IllegalStateException("Unknwon location of configuration source.");
		
		return new PropertyLoader()
			.setPropertyLocation(location)
			.load();
	}

	public Class<?> getObjectType() {
		return Configuration.class;
	}

	public boolean isSingleton() {
		return true;
	}

	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
}
